from django.db import models
import uuid
from multiselectfield import MultiSelectField


class Membership(models.Model):
    vid = models.UUIDField(primary_key=True, auto_created=True,
                           default=uuid.uuid4, editable=False,
                           verbose_name=u'vip uuid',
                           help_text="vip uuid"
                           )
    vip_name = models.CharField(max_length=50, null=False)
    CLASS_CHOICE = (
        (u'v0', u'普通会员'),
        (u'v1', u'青铜会员'),
        (u'v2', u'白银会员'),
        (u'v3', u'黄金会员'),
        (u'v4', u'铂金会员'),
        (u'v5', u'钻石会员'),
    )
    vip_class = models.CharField(max_length=2, choices=CLASS_CHOICE, default='v0')
    GENDER_CHOICE = (
        (u'M', u'Male'),
        (u'F', u'Female'),
    )
    vip_gender = models.CharField(max_length=2, choices=GENDER_CHOICE, blank=True)
    vip_phone = models.CharField(max_length=11, blank=True)
    vip_birthday = models.DateField(blank=True)
    vip_email = models.EmailField(max_length=100, blank=True, null=True)
    vip_address = models.CharField(max_length=150, blank=True, null=True)
    vip_point = models.IntegerField(default=0)
    # vip_order = models.ForeignKey('Order', related_name='Membership_Order', on_delete=models.CASCADE)
    vip_coupon = models.ForeignKey('coupon', related_name='Membership_Coupon', on_delete=models.CASCADE, verbose_name='优惠券')

    Create_Date = models.DateTimeField(auto_now_add=True)
    Modify_date = models.DateTimeField(auto_now=True)

    class Meta:
        # app_lable的值为APP的名称，这样就可以将models定义到多个文件中了
        app_label = 'Rufe'
        db_table = 'Membership'
        verbose_name = 'Membership'
        ordering = ['-vid', ]

    def __str__(self):
        return self.vip_name


class Coupon(models.Model):
    cid = models.UUIDField(primary_key=True, auto_created=True,
                           default=uuid.uuid4, editable=False,
                           verbose_name=u'Coupon uuid',
                           help_text="Coupon uuid"
                           )
    SCOPE_CHOICE = (
        (u'v0', u'普通会员'),
        (u'v1', u'青铜会员'),
        (u'v2', u'白银会员'),
        (u'v3', u'黄金会员'),
        (u'v4', u'铂金会员'),
        (u'v5', u'钻石会员'),
    )
    coupon = models.CharField(max_length=50, null=False)
    coupon_value = models.IntegerField(default=0)
    coupon_scope = MultiSelectField(choices=SCOPE_CHOICE, null=True, blank=True, verbose_name='优惠券范围')
    Create_Date = models.DateTimeField(auto_now_add=True)
    Start_Date = models.DateTimeField(blank=True, null=True, verbose_name='优惠券开始时间')
    End_Date = models.DateTimeField(blank=True, null=True, verbose_name='优惠券结束时间')
    isActive = models.BooleanField(default=True, verbose_name='优惠券是否有效')
    Modify_date = models.DateTimeField(auto_now=True)

    class Meta:
        app_label = 'Rufe'
        db_table = 'Coupon'
        verbose_name = 'Coupon'
        ordering = ['-cid', ]

    def __str__(self):
        return self.coupon

